package com.test.mcdonald;

import java.util.List;

public class ClientMy  {
	Thread curClientThread;
	Dish dish;

	public ClientMy() {
		dish = new Dish();
		cashier = choseCashier();
//		curClientThread = new Thread(this);
//		curClientThread.start();
	}

	public Thread getCurClientThread() {
		return curClientThread;
	}

	private Cashier cashier;

	public void payMoney(float money) {
	}

	public Cashier choseCashier() {
		int minQueue = GlobalSettings.MAX_CLIENTS;
		Cashier freeCashier = !McDonald.cashierList.isEmpty() ? McDonald.cashierList.get(0) : null;
		synchronized (McDonald.cashierList) {
			for (Cashier cashier : McDonald.cashierList) {
				if (cashier.queueClients.size() < minQueue) {
					minQueue = cashier.queueClients.size();
					freeCashier = cashier;
				}
			}
			if (freeCashier == null)
				throw new NullPointerException(
						"NullPointerException freeCashier == null");
			System.out.print("Client chose Name cashier:"
					+ freeCashier.getNameCashier() + "\n");
			freeCashier.queueClients.add(this);
		}

		return freeCashier;
	}

	
}
